﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Collections;
using System.Windows.Documents;

namespace TimersXP
{
    public class TimersHostViewModel : INotifyPropertyChanged
    {
        /// <summary>The timers core</summary>
        private TimersCore timersCore = TimersCore.GetTimersCore();

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        /// <summary>Initializes a new instance of the <see cref="TimersHostViewModel"/> class.</summary>
        public TimersHostViewModel()
        {
            // Load the default skin.
            this.ApplySkinFromMenuItem(timersCore.SkinsLibrary.LoadedSkins[0]);
        }

        /// <summary>Called when [menu item click].</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        public void OnMenuItemClick(object sender, RoutedEventArgs e)
        {
            // Find out which skin was selected from the menu.
            SkinItem selectedSkin = e.OriginalSource as SkinItem;

            // Load the selected skin.
            this.ApplySkinFromMenuItem(selectedSkin);
        }

        /// <summary>Applies the skin from menu item.</summary>
        /// <param name="skin">The skin.</param>
        void ApplySkinFromMenuItem(SkinItem skin)
        {
            // Get a relative path to the ResourceDictionary which contains the selected skin.
            string skinPath = skin.SkinPath;
            Uri skinDictUri = new Uri(skinPath, UriKind.Relative);

            // Tell the Application to load the skin resources.
            App app = Application.Current as App;
            app.ApplySkin(skinDictUri);
        }
    }
}
